﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQwithSampleTypeArray
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] values = { 5, 3, 6, 7, 1, 0, 2, 6 };

            Display(values, "The orignal array :");

            var filter =
                from value in values
                where value > 4
                select value;

            Display(filter, "Array values greater than 4 :");

            var sorted = 
                from value in values
                orderby value descending
                select value;

            Display(sorted, "Original array, sorted :");

            var sortFilterResult =
                from value in filter
                orderby value descending
                select value;

            Display(sortFilterResult, "Values greater than 4, descending order(separately :");
                
            var sortAndFilter =
                from value in values
                where value > 4
                orderby value descending
                select value;

            Display(sortAndFilter, "Values greater than 4, descending order(one query) :");

            Console.ReadKey();
        }//end Main

        public static void Display(IEnumerable<int> results, string header)
        {
            Console.Write("{0}",header);

            foreach (var element in results)
            {
                Console.Write(" {0}",element);
            }//end for

            Console.WriteLine();
        }//end method Display
    }
}
